package com.metagurukul.metagranth.model.common.dbutil;

import java.sql.Connection;


import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Purpose of Util class is close the ResultSet and Statement object.
 * 
 * @author dheeraj kumar
 * 
 */

public class Util {

	/**
	 * closeResultSet(ResultSet) method for close the ResultSet object.
	 * 
	 * @param rs
	 *            ResultSet object
	 */
	public static void closeResultSet(ResultSet rs) {
		try {
			if (rs != null) {
				rs.close();
				rs = null;
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}

	/**
	 * closeStatement(Statement) method for close the Statement object.
	 * 
	 * @param stmt
	 *            Statement object
	 */
	public static void closeStatement(Statement stmt) {
		try {
			if (stmt != null) {
				stmt.close();
				stmt = null;
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}
	
	/**
	 * closePreparedStatement(PreparedStatement) method for close the PreparedStatement object.
	 * 
	 * @param pstmt
	 *            PreparedStatement object
	 */
	public static void closePreparedStatement(PreparedStatement pstmt) {
		try {
			if (pstmt != null) {
				pstmt.close();
				pstmt = null;
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}

	/**
	 * closeConnection() method is for close a connection object
	 * 
	 * @param con
	 *            Connection object
	 */
	public static void closeConnection(Connection con) {
		try {
			if (con != null) {
				con.close();
				con = null;
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}
}
